package com.h5lib.xlsx4j;

import java.io.IOException;
import java.util.Iterator;

import org.xmlpull.v1.XmlPullParserException;

public class XLSXSheetRowIterator implements Iterator<XLSXSheetRow> {

    private XMLSheetReader reader;

    private XLSXSheetRow next;

    public XLSXSheetRowIterator(XMLSheetReader sheetReader) {
        reader = sheetReader;
    }

    @Override
    public boolean hasNext() {

        if( next == null ) {
            next = fetch();
        }

        return next != null;
    }

    @Override
    public XLSXSheetRow next() {

        XLSXSheetRow row = null;

        if( hasNext() ) {
            row = next;
            next = null;
        }

        return row;
    }

    private XLSXSheetRow fetch() {
        XLSXSheetRow row = null;
        try {
			row = reader.next();
		} catch (NumberFormatException e) {
			e.printStackTrace();
		} catch (XmlPullParserException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
        return row;
    }

    @Override
    public void remove() {  }
}
